﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace bll
{
    public class checkString
    {
        public String checkIt(String _s, String _category)
        {
            String s = "";
            switch (_category)
            {
                case "password": s = checkPW(_s); break;
                case "name": s = checkName(_s); break;
                case "email": s = checkEmail(_s); break;
                case "hourlyRate": s = checkHourlyRate(_s); break;
                case "costs": s = checkCosts(_s); break;
                case "hours": s = checkHours(_s); break;
                case "phoneNr": s = checkPhoneNr(_s); break;
                default: break;
            }


            return s;
        }

        protected String checkPW(String _pw)
        {
            String _solution = "";
            char[] _c = _pw.ToCharArray();
            bool uC = false;
            bool nbr = false;

            if (_pw.Length < 4 || _pw.Length > 25)
            {
                _solution += "It's to long (more than 25) or to short (less than 4). ";
            }
            else
            {
                for (int i = 0; i < _c.Length; i++)
                {

                    if (Char.IsNumber(_c[i]))
                    {
                        nbr = true;
                    }
                    if (Char.IsUpper(_c[i]))
                    {
                        uC = true;
                    }
                    if (Char.IsSymbol(_c[i]) || Char.IsPunctuation(_c[i]))
                    {
                        _solution += "Please just use letters and numbers. ";
                    }
                }

                if (nbr != true || uC != true)
                {
                    _solution += "Please use at least 1 capital letter and 1 number. ";
                }
            }
            return _solution;
        }//checkPW()

        protected String checkName(String _name)
        {
            String _solution = "";
            char[] _c = _name.ToCharArray();

            if (_name.Length < 1 || _name.Length > 40)
            {
                _solution += "It's to long (more than 40) or to short (less than 1). ";
            }
            else
            {
                bool check1 = false;
                bool check2 = false;

                for (int i = 0; i < _c.Length; i++)
                {
                    if (Char.IsNumber(_c[i]) && check1 == false)
                    {
                        check1 = true;
                        _solution += "Numbers are not allowed in a Name. ";
                    }
                    if ((Char.IsSymbol(_c[i]) || Char.IsPunctuation(_c[i])) && _c[i] != '-' && check2 == false)
                    {
                        check2 = true;
                        _solution += "Symbols and Punctuation is not allowed (only '-'). ";
                    }
                }
            }
            return _solution;
        }//checkName()

        protected String checkEmail(String _email)
        {
            String _solution = "";
            char[] _c = _email.ToCharArray();
            bool _at = false; 
            bool _punct = false;

            if (_email.Length < 4 || _email.Length > 50)
            {
                _solution += "It's to long (more than 50) or to short (less than 4). ";
            }
            else
            {
                for (int i = 0; i < _c.Length; i++)
                {
                    if (_c[i] == '@')
                    {
                        _at = true;
                    }
                    if (_c[i] == '.')
                    {
                        _punct = true;
                    }

                }

                if (_at != true || _punct != true)
                {
                    _solution += "It seems to be no real email address! ";
                }
            }
            return _solution;
        }//checkEmail()

        protected String checkHourlyRate(String _hr)
        {
            String _solution = "";
            char[] _c = _hr.ToCharArray();

            if (_hr.Length < 1 || _hr.Length > 5)
            {
                _solution += "Sry! It seems to be no real hourly rate! ";
            }
            else
            {
                for (int i = 0; i < _c.Length; i++)
                {
                    if (!Char.IsNumber(_c[i]))
                    {
                        _solution += "Only numbers. (" + _c[i] + " is not allowed!) ";
                        break;
                    }

                }
            }
            return _solution;
        }//checkHourlyRate()


        protected String checkCosts(String _costs)
        {
            String _solution = "";
            char[] _c = _costs.ToCharArray();

            if (_costs.Length < 1 || _costs.Length > 10)
            {
                _solution += "The Costs don't seem realistic! ";
            }
            else
            {
                for (int i = 0; i < _c.Length; i++)
                {
                    if (!Char.IsNumber(_c[i]))
                    {
                        _solution += "Only numbers. (" + _c[i] + " is not allowed!) ";
                        break;
                    }
                }
            }
            return _solution;
        }//checkCosts()

        protected String checkHours(String _hours)
        {
            String _solution = "";
            char[] _c = _hours.ToCharArray();
            bool _isLetter = false;
                for (int i = 0; i < _c.Length; i++)
                {
                    if (!Char.IsNumber(_c[i]))
                    {
                        _solution += "Only numbers. (" + _c[i] + " is not allowed!) ";
                        _isLetter = true;
                        break;
                    }
                }
                if (_isLetter == false)
                {
                    if (Convert.ToInt32(_hours) < 1)
                    {
                        _solution += "Please enter at least 1 hour! ";
                    }
                    if (Convert.ToInt32(_hours) > 24)
                    {
                        _solution += "You can't work 24h at a time! ";
                    }
                }
            return _solution;
        }//checkHours()


        protected String checkPhoneNr(String _nr)
        {
            String _solution = "";
            char[] _c = _nr.ToCharArray();
            if (_nr.Length < 3 || _nr.Length > 30)
            {
                _solution += "Number is either too short or too large. ";
            }
            else{
                for (int i = 0; i < _c.Length; i++)
                {
                    if (!Char.IsLetter(_c[i]))
                    {
                        _solution += "You can't use letters in a phone number! (" + _c[i] + " is not allowed!) ";
                        break;
                    }
                }
            }
            return _solution;
        }//checkPhoneNr()
    }
}
